<template>
    <div class="home">
        <!--<h2>主页</h2>-->
        <!--<el-button @click="logout">退出登录</el-button>-->
        <el-container class="homeContainer">
            <el-header>
                <div class="headerCon">
                    <img src="../assets/logo.png" alt="logo">
                    <span>电商后台管理系统</span>
                </div>
                <el-button type="info" @click="logout">退出</el-button>
            </el-header>
            <el-container>
                <el-aside :width="isCollapse ? '64px':'200px'">
                    <div class="toggle-button" @click="isCollapse = !isCollapse">|||</div>
                    <el-menu
                            :default-active="$route.path"
                            router
                            :collapse="isCollapse"
                            :collapse-transition="false"
                            :unique-opened="true"
                            class="el-menu-vertical-demo"
                            @open="handleOpen"
                            @close="handleClose"
                            background-color="#333744"
                            text-color="#fff"
                            active-text-color="#ffd04b">
                        <el-submenu :index="item.id+''" v-for="item in menuList" :key="item.id">
                            <template slot="title">
                                <i :class="iconsObj[item.id]"></i>
                                <span>{{item.authName}}</span>
                            </template>
                            <el-menu-item v-for="item2 in item.children" :key="item2.id" :index="'/'+item2.path">
                                <i class="el-icon-location"></i>
                                {{item2.authName}}
                            </el-menu-item>
                        </el-submenu>
                    </el-menu>
                </el-aside>
                <el-main>
                    <router-view></router-view>
                </el-main>
            </el-container>
        </el-container>
    </div>
</template>

<script>


    export default {
        name: 'Home',
        created(){
            this.getMenusData();
        },
        data(){
            return {
                isCollapse: false,
                menuList: [],
                iconsObj: {
                    '125': 'iconfont icon-user',
                    '103': 'iconfont icon-tijikongjian',
                    '101': 'iconfont icon-shangpin',
                    '102': 'iconfont icon-danju',
                    '145': 'iconfont icon-baobiao'
                },
                iconsLcon: {
                    110: "el-icon-s-check",
                    111: "el-icon-user",
                    112: "el-icon-setting",
                    104: "el-icon-s-grid",
                    115: "el-icon-document-copy",
                    121: "el-icon-s-data",
                    107: "el-icon-edit-outline",
                    146: "el-icon-office-building",
                },
            }
        },
        methods: {
            logout(){
                window.sessionStorage.removeItem("token");
                this.$router.push("/login")
            },
            async getMenusData(){
                let {data: res} = await this.$http.get("menus");
                if (res.meta.status !== 200) return this.$message.error(res.meta.msg);
                this.menuList = res.data;
                console.log("menus=>", res)
            },
            handleOpen(){
            },
            handleClose(){
            },
        },
    }
</script>
<style lang="scss" type="text/scss">
    .homeContainer {

        /*height: 100%;*/
        height: 100vh;
    }

    .el-header {
        background-color: #373d41;
        display: flex;
        justify-content: space-between;
        padding-left: 0;
        align-items: center;
        color: #fff;
        font-size: 20px;
        > div {
            display: flex;
            align-items: center;
            img {
                transform: scale(0.20);
            }
            span {
                margin-left: 15px;
            }
        }
    }

    .el-aside {
        background-color: #333744;
        .el-menu {
            border-right: none;
        }
    }

    .el-main {
        background-color: #eaedf1;
    }

    .iconfont {
        margin-right: 10px;
    }

    .toggle-button {
        background-color: #4a5064;
        font-size: 10px;
        line-height: 24px;
        color: #fff;
        text-align: center;
        letter-spacing: 0.2em;
        cursor: pointer;
    }
</style>

